﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.CRM.Bussiness;
using System.Data;
using ZX.CRM.Report.CrmReport;


namespace ZX.WebApp.Crm.Report.TuiGuang
{
    public partial class RptValue : System.Web.UI.Page
    {
        BCrmRptTuiguang Tuiguang = new BCrmRptTuiguang();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtStime.Value = DateTime.Now.Year.ToString() + "-01-01";
                txtEtime.Value = DateTime.Now.ToShortDateString();
            }
            if (txtStime.Value != "")
            {
                if (txtEtime.Value == "")
                {
                    txtEtime.Value = DateTime.Now.ToString();
                }
                DoReport(1, txtStime.Value, txtEtime.Value);
            }
            else
            {
                DoReport(0, txtStime.Value, txtEtime.Value);
            }
        }
        private void DoReport(int type, string sDate, string eDate)
        {
            try
            {
                DataSet myDataSet = new DataSet();
                myDataSet.DataSetName = "DsCrmRptyuechangTuiGuang";
                DataTable CityDataTable = Tuiguang.ReturnTableValueCity(0, Convert.ToDateTime(sDate), DateTime.Parse(eDate));
                DataTable TradeDataTable = Tuiguang.ReturnTableValueTrade(0, Convert.ToDateTime(sDate), DateTime.Parse(eDate));
                DataTable ProductDataTable = Tuiguang.ReturnTableValueProduct(0, Convert.ToDateTime(sDate), DateTime.Parse(eDate));
                DataTable PersonDataTable = Tuiguang.ReturnTableValuePerson(0, Convert.ToDateTime(sDate), DateTime.Parse(eDate));
                CityDataTable.TableName = "DsYuechangCity";
                TradeDataTable.TableName = "DsYuechangTrade";
                ProductDataTable.TableName = "DsYuechangProduct";
                PersonDataTable.TableName = "DsYuechangPerson";
                myDataSet.Tables.Add(CityDataTable.Copy());
                myDataSet.Tables.Add(TradeDataTable.Copy());
                myDataSet.Tables.Add(ProductDataTable.Copy());
                myDataSet.Tables.Add(PersonDataTable.Copy());
                RptValueTuiguang crm = new RptValueTuiguang();
                crm.DataSource = myDataSet;
                RV.Report = crm;
            }
            catch
            {
            }


            //}
        }
        /// <summary>
        /// 查询按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            DoReport(1, txtStime.Value, txtEtime.Value);
        }
    }
}